package org.codeart.command.example01;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 服务员类 调用者
 */
@Data
public class Waiter {

    // 持有多个命令对象
    private List<Command> commands;

    public Waiter() {
        this.commands = new ArrayList<>();
    }

    public Waiter(List<Command> commands) {
        this.commands = commands;
    }
    
    public void addCommand(Command command) {
        commands.add(command);
    }
    
    // 发出指令
    public void orderUp() {
        System.out.println("叮咚!服务员: 有新的订单, 请师傅开始制作......");
        for (Command command : commands) {
            if (command != null) {
                command.execute();
            }
        }
    }
}
